package net.lab1024.smartadmin.module.business.engineReverse.controller;

import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.controller.BaseController;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.common.domain.ValidateList;
import net.lab1024.smartadmin.module.business.engineExternalCharacteristic.domain.entity.EngineExternalCharacteristicEntity;
import net.lab1024.smartadmin.module.business.engineReverse.domain.dto.EngineReverseAddDTO;
import net.lab1024.smartadmin.module.business.engineReverse.domain.dto.EngineReverseUpdateDTO;
import net.lab1024.smartadmin.module.business.engineReverse.domain.dto.EngineReverseQueryDTO;
import net.lab1024.smartadmin.module.business.engineReverse.domain.entity.EngineReverseEntity;
import net.lab1024.smartadmin.module.business.engineReverse.domain.vo.EngineReverseVO;
import net.lab1024.smartadmin.module.business.engineReverse.domain.vo.EngineReverseExcelVO;
import net.lab1024.smartadmin.module.business.engineReverse.service.EngineReverseService;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import org.apache.poi.ss.usermodel.Workbook;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * [ 倒拖特性曲线 ]
 *
 * @author wuhq
 * @version 1.0
 * @company 倒拖特性曲线
 * @copyright (c)  倒拖特性曲线Inc. All rights reserved.
 * @date 2021-11-07 11:17:29
 * @since JDK1.8
 */
@RestController
@Api(tags = {"倒拖特性曲线"})
public class EngineReverseController extends BaseController {

    @Autowired
    private EngineReverseService engineReverseService;

    @ApiOperation(value = "分页查询倒拖特性曲线",notes = "@author wuhq")
    @PostMapping("/engineReverse/page/query")
    public ResponseDTO<PageResultDTO<EngineReverseVO>> queryByPage(@RequestBody EngineReverseQueryDTO queryDTO) {
        return engineReverseService.queryByPage(queryDTO);
    }

    @ApiOperation(value = "添加倒拖特性曲线",notes = "@author wuhq")
    @PostMapping("/engineReverse/add")
    public ResponseDTO<String> add(@RequestBody @Validated EngineReverseAddDTO addTO){
        engineReverseService.delByEngineId(addTO.getEngineId());
        return engineReverseService.add(addTO);
    }
    @ApiOperation(value = "根据发动机id获取数据",notes = "@author wuhq")
    @GetMapping("/engineReverse/getByEngineId/{engineId}")
    public ResponseDTO<EngineReverseEntity> getByEngineId(@PathVariable Long engineId) {
        return ResponseDTO.succData(engineReverseService.getByEngineId(engineId));
    }


    @ApiOperation(value = "根据id获取数据",notes = "@author wuhq")
    @GetMapping("/engineReverse/getById/{id}")
    public ResponseDTO<EngineReverseEntity> getById(@PathVariable Long id) {
        return ResponseDTO.succData(engineReverseService.getById(id));
    }


    @ApiOperation(value="修改倒拖特性曲线",notes = "@author wuhq")
    @PostMapping("/engineReverse/update")
    public ResponseDTO<String> update(@RequestBody @Validated EngineReverseUpdateDTO updateDTO){
        return engineReverseService.update(updateDTO);
    }

    @ApiOperation(value="批量删除倒拖特性曲线",notes = "@author wuhq")
    @PostMapping("/engineReverse/deleteByIds")
    public ResponseDTO<String> delete(@RequestBody @Validated ValidateList<Long> idList) {
        return engineReverseService.deleteByIds(idList);
    }

    @ApiOperation(value = "批量导出", notes = "@author wuhq")
    @PostMapping("/engineReverse/export/batch")
    public void batchExport(@RequestBody @Validated ValidateList<Long> idList, HttpServletResponse response) {
        //查询数据
        List<EngineReverseExcelVO> engineReverseList = engineReverseService.queryBatchExportData(idList);
        //导出操作
        ExportParams ex = new ExportParams("倒拖特性曲线", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, EngineReverseExcelVO.class, engineReverseList);
        downloadExcel("倒拖特性曲线", workbook, response);
    }

    @ApiOperation(value = "导出全部", notes = "@author wuhq")
    @PostMapping("/engineReverse/export/all")
    public void exportAll(@RequestBody @Validated EngineReverseQueryDTO queryDTO, HttpServletResponse response) {
        //查询数据
        List<EngineReverseExcelVO> engineReverseList = engineReverseService.queryAllExportData(queryDTO);
        //导出操作
        ExportParams ex = new ExportParams("倒拖特性曲线", "Sheet1");
        Workbook workbook = ExcelExportUtil.exportExcel(ex, EngineReverseExcelVO.class, engineReverseList);
        downloadExcel("倒拖特性曲线", workbook, response);
    }

}
